package day01.linkedList模拟;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * @author feng
 * @Date 2021/10/17 14:04
 * ConcurrentModificationException 并发修改异常
 */
public class ListIteratorTest {
    public static void main(String[] args) {
        List mylist = new ArrayList();
        mylist.add("aa");
        mylist.add("bb");
        mylist.add("cc");
        mylist.add("dd");
        Iterator iterator = mylist.iterator();
        while (iterator.hasNext()) {
            // mylist.add("ee");
            System.out.println(iterator.next());
        }

        System.out.println("-----------");
        ListIterator listIterator = mylist.listIterator();
        while (listIterator.hasNext()) {
            System.out.println(listIterator.next());
            if ("cc".equals(listIterator.next())){
                   listIterator.add("ee");
            }

        }

    }
}
